package fat
{

import com.fit4as.fit.*;
import mx.utils.StringUtil;
import com.fit4as.util.io.StringWriter;

public class StandardAnnotationFixture extends ColumnFixture
{
    public var OriginalHTML : String = "Text";
    public var Annotation : String;
    public var Text : String;

    public function Output() : String {
        var parse : Parse = Parse.createParse(OriginalHTML, ["td"]);
        var testbed : Fixture = new Fixture();

        if (Annotation == "right") testbed.right(parse);
        if (Annotation == "wrong") testbed.wrong(parse, Text);
        if (Annotation == "error") testbed.error(parse, Text);
        if (Annotation == "info") testbed.info(parse, Text);
        if (Annotation == "ignore") testbed.ignore(parse);

        return GenerateOutput(parse);
    }

    override public function doCell(cell : Parse, column : int) : void {
        //t race("doCell " + [ column, cell.text(), cell.text() == "" ]);
        try {
            if (column == 4) {
                cell.body = RenderedOutput();
            }
            else {
                super.doCell(cell, column);
            }
        }
        catch (e : Exception) {
            exception(cell, e);
        }
    }

    public function RenderedOutput() : String {
        return "<table border='1'><tr>" + Output() + "</tr></table>";
    }

    // code smell note: copied from ParseFixture
    private function GenerateOutput(parse : Parse) : String {
        var result : StringWriter = new StringWriter();
        parse.print(result);
        return StringUtil.trim(result.getContent());
    }
}
}